package com.zty.schedule.api;

import com.zty.schedule.entity.JsonResult;
import com.zty.schedule.service.ValueRecordService;
import com.zty.schedule.service.ValueService;
import com.zty.schedule.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(description = "产值接口")
@RestController
@RequestMapping("Value")
@CrossOrigin
public class ValueController {
    @Autowired
    private ValueService valueService;

    @ApiOperation(value = "增加总产值",notes = "")
    @PostMapping("/InsertValue")
    public JsonResult InsertValue(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = valueService.InsertValue(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("增加成功!");
        }else {
            jsonResult.setCode(200);
            jsonResult.setMessage("增加失败!");
        }
        return jsonResult;
    }


    @ApiOperation(value = "删除总产值",notes = "")
    @PostMapping("/DeleteValue")
    public JsonResult DeleteValue(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = valueService.DeleteValue(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("增加成功!");
        }else {
            jsonResult.setCode(200);
            jsonResult.setMessage("增加失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改总产值",notes = "")
    @PostMapping("/UpdateValue")
    public JsonResult UpdateValue(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = valueService.UpdateValue(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("增加成功!");
        }else {
            jsonResult.setCode(200);
            jsonResult.setMessage("增加失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "查询总产值",notes = "")
    @PostMapping("/FindValue")
    public Page FindValue(@RequestBody Map map){
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        long i=1;
        page.setTotal(i);
        page.setItems(valueService.FindValue(map));
        return page;
    }
}
